home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / libv7 / getcwd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-12  |  490 b   |  31 lines

  1. /*
  2.  * SystemV getcwd simulation, courtesy peter honeyman
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7.  
  8. /* imports from libc */
  9. extern FILE *popen();
  10.  
  11. char *
  12. getcwd(path, size)
  13. register char *path;
  14. int size;
  15. {
  16.     register char *nlp;
  17.     register FILE *fp;
  18.  
  19.     fp = popen("PATH=/bin:/usr/bin pwd", "r");
  20.     if (fp == NULL)
  21.         return 0;
  22.     if (fgets(path, size, fp) == NULL) {
  23.         (void) pclose(fp);
  24.         return 0;
  25.     }
  26.     if ((nlp = strrchr(path, '\n')) != NULL)
  27.         *nlp = '\0';
  28.     (void) pclose(fp);
  29.     return path;
  30. }
  31.